package com.liberty.dasheen.admin.sys.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.liberty.dasheen.admin.sys.service.MenuService;
import com.liberty.dasheen.common.BaseController;
import com.liberty.dasheen.config.shiro.realm.ShiroDbRealm;
import com.liberty.dasheen.entity.SysMenu;

@Controller
@RequestMapping("/admin/sys/menu")
public class MenuController extends BaseController {
	
	private static final Logger log = LoggerFactory.getLogger(ShiroDbRealm.class);
	
	@Autowired
	private MenuService menuService;

	@RequestMapping("/tree")
	@ResponseBody
	public List<SysMenu> treeMenu(@RequestBody String json) {
		try {
			if (json == null || "".equals(json)) {
				return null;
			}
			SysMenu menu = super.jsonToObject(json, SysMenu.class);
			List<SysMenu> list = menuService.listMenuByPId(menu.getPid());
			return list;
		} catch (Exception e) {
			System.out.println("MenuController | treeMenu | Exception:" + e);
			return null;
		}
	}
}
